home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Languguage OS 2
/
Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO
/
language
/
ici
/
ici.cpi
/
mkstruct.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-27
|
2KB
|
91 lines
#include "object.h"
#include <varargs.h>
/*
* mkstruct(struct, "i st_mode i st_ino i st_dev", mode, ino, dev)
*/
struct_t *
mkstruct(va_alist)
va_dcl
{
va_list va;
struct_t *s; /* Arg 1. */
register char *fmt; /* Arg 2. */
register char *p;
register object_t *o;
register struct_t *d;
string_t *n;
va_start(va);
s = va_arg(va, struct_t *);
fmt = va_arg(va, char *);
if ((d = s) == NULL)
{
if ((d = new_struct()) == NULL)
return NULL;
}
n = NULL;
o = NULL;
while (*fmt != '\0')
{
for (p = &fmt[2]; *p != ' ' && *p != '\0'; ++p)
;
switch (*fmt)
{
case 'i':
if ((o = objof(new_int((long)va_arg(va, int)))) == NULL)
goto fail;
break;
case 'l':
if ((o = objof(new_int(va_arg(va, long)))) == NULL)
goto fail;
break;
case 'f':
if ((o = objof(new_float(va_arg(va, double)))) == NULL)
goto fail;
break;
case 's':
if ((o = objof(new_cname(va_arg(va, char *)))) == NULL)
goto fail;
break;
case 'o':
if ((o = va_arg(va, object_t *)) == NULL)
{
o = objof(&o_null);
got(o);
}
break;
default:
error = "illegal structure fill";
goto fail;
}
fmt += 2;
if ((n = new_name(fmt, p - fmt)) == NULL)
goto fail;
if (assign(objof(d), objof(n), o))
goto fail;
loose(o);
loose(n);
n = NULL;
o = NULL;
if (*(fmt = p) == '\0')
break;
++fmt;
}
return d;
fail:
if (o != NULL && o != objof(&o_null))
loose(o);
if (n != NULL)
freeo(n);
if (s == NULL)
freeo(d);
return NULL;
}